package me.zk.practice1.s;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author zhangkai
 * @date 2023/7/15 12:00
 */
public class LS_Offer_32_1 {
    public int[] levelOrder(TreeNode root) {
        if (root == null) {
            return new int[]{};
        }
        Queue<TreeNode> queue = new LinkedList<>();
        LinkedList<Integer> res = new LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();
            res.add(node.val);
            if (node.left!=null) {
                queue.add(node.left);
            }
            if (node.right != null) {
                queue.add(node.right);
            }

        }
        int[] r = new int[res.size()];
        int index = 0;
        for (Integer i : res) {
            r[index++] = i;
        }
        return r;
    }


}
